package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.ProductTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.ProductType;
import com.ruoyi.system.service.IProductTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 产品类型Controller
 * 
 * @author ruoyi
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/productType")
public class ProductTypeController extends BaseController
{
    @Autowired
    private IProductTypeService productTypeService;

    /**
     * 查询产品类型列表
     */
    @RequiresPermissions("system:productType:list")
    @GetMapping("/list")
    public AjaxResult list(ProductType productType)
    {
        List<ProductTypeVo> list = productTypeService.selectProductTypeList(productType);
        return success(list);
    }

    /**
     * 查询所有产品类型列表
     */
    @RequiresPermissions("system:productType:all")
    @GetMapping("/all")
    public List<ProductType> all()
    {
        return productTypeService.selectAllProductTypeList();
    }

    /**
     * 导出产品类型列表
     */
    @RequiresPermissions("system:productType:export")
    @Log(title = "产品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductType productType)
    {
        List<ProductTypeVo> list = productTypeService.selectProductTypeList(productType);
        ExcelUtil<ProductTypeVo> util = new ExcelUtil<ProductTypeVo>(ProductTypeVo.class);
        util.exportExcel(response, list, "产品类型数据");
    }

    /**
     * 获取产品类型详细信息
     */
    @RequiresPermissions("system:productType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productTypeService.selectProductTypeById(id));
    }

    /**
     * 新增产品类型
     */
    @RequiresPermissions("system:productType:add")
    @Log(title = "产品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductType productType)
    {
        return toAjax(productTypeService.insertProductType(productType));
    }

    /**
     * 修改产品类型
     */
    @RequiresPermissions("system:productType:edit")
    @Log(title = "产品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductType productType)
    {
        return toAjax(productTypeService.updateProductType(productType));
    }

    /**
     * 删除产品类型
     */
    @RequiresPermissions("system:productType:remove")
    @Log(title = "产品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productTypeService.deleteProductTypeByIds(ids));
    }
}
